package com.industrial.operation.controller;

import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;

import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.industrial.common.log.annotation.Log;
import com.industrial.common.log.enums.BusinessType;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.operation.domain.OperationKnowledgeManage;
import com.industrial.operation.service.IOperationKnowledgeManageService;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.utils.poi.ExcelUtil;
import com.industrial.common.core.web.page.TableDataInfo;

/**
 * 知识动态管理Controller
 * 
 * @author ZHOU_S
 * @date 2024-02-20
 */
@RestController
@RequestMapping("/manage")
public class OperationKnowledgeManageController extends BaseController
{
    @Autowired
    private IOperationKnowledgeManageService operationKnowledgeManageService;

    /**
     * 查询知识动态管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OperationKnowledgeManage operationKnowledgeManage)
    {
        startPage();
        List<OperationKnowledgeManage> list = operationKnowledgeManageService.selectOperationKnowledgeManageList(operationKnowledgeManage);
        return getDataTable(list);
    }

    /**
     * 导出知识动态管理列表
     */
    @RequiresPermissions("operation:manage:export")
    @Log(title = "知识动态管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperationKnowledgeManage operationKnowledgeManage)
    {
        List<OperationKnowledgeManage> list = operationKnowledgeManageService.selectOperationKnowledgeManageList(operationKnowledgeManage);
        ExcelUtil<OperationKnowledgeManage> util = new ExcelUtil<OperationKnowledgeManage>(OperationKnowledgeManage.class);
        util.exportExcel(response, list, "知识动态管理数据");
    }

    /**
     * 获取知识动态管理详细信息
     */
    @GetMapping(value = "/{baseId}")
    public AjaxResult getInfo(@PathVariable("baseId") String baseId)
    {
        OperationKnowledgeManage operationKnowledgeManage=  operationKnowledgeManageService.selectOperationKnowledgeManageByBaseId(baseId);
        return success(operationKnowledgeManage);
    }

    /**
     * 新增知识动态管理
     */
    @RequiresPermissions("operation:manage:add")
    @Log(title = "知识动态管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperationKnowledgeManage operationKnowledgeManage)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> roles= loginUser.getRoles();
        if(roles.contains("q_01_001")){
            return  warn("无此审核权限!");
        }else{
        return toAjax(operationKnowledgeManageService.insertOperationKnowledgeManage(operationKnowledgeManage));
        }
    }

    /**
     * 修改知识动态管理
     */
    @RequiresPermissions("operation:manage:edit")
    @Log(title = "知识动态管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperationKnowledgeManage operationKnowledgeManage)
    {
        return toAjax(operationKnowledgeManageService.updateOperationKnowledgeManage(operationKnowledgeManage));
    }

    /**
     * 删除知识动态管理
     */
    @RequiresPermissions("operation:manage:remove")
    @Log(title = "知识动态管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{baseIds}")
    public AjaxResult remove(@PathVariable String[] baseIds)
    {
        return toAjax(operationKnowledgeManageService.deleteOperationKnowledgeManageByBaseIds(baseIds));
    }

    @RequiresPermissions("operation:manage:examine")
    @Log(title = "知识动态管理审核", businessType = BusinessType.UPDATE)
    @PutMapping("/examine")
    public AjaxResult examine(@RequestBody OperationKnowledgeManage operationKnowledgeManage)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Set<String> roles= loginUser.getRoles();
        if(!roles.contains("p_01_011")){
            return  warn("无此审核权限!");
        }else{
            operationKnowledgeManage.setStatusTime(new Date());
            operationKnowledgeManage.setRejectioner(loginUser.getUsername());
            return toAjax(operationKnowledgeManageService.updateOperationKnowledgeManage(operationKnowledgeManage));
        }
    }
}
